<!doctype html>
<html>
<head>
<meta name="apple-mobile-web-app-capable" content="yes">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0">
<title>主播</title>
<link href="../../css/newStyle.css" type="text/css" rel="stylesheet" />
<script type="text/javascript" src="../../js/jquery-1.7.2.min.js"></script>
<script type="text/javascript" src="../../js/common.js"></script>
<script type="text/javascript" src="../../js/gbRst.js"></script>
<script type="text/javascript" src="../../js/utils.js"></script>
<script type="text/javascript" src="../../js/openId.js"></script>
<script type="text/javascript" src="../../js/header&footer.js"></script>
<script type="text/javascript" src="../../js/qmsk-1.2.js"></script>
<script type="text/javascript">
$(function() {

	showVoteinfo();
});
var localip;
var openId;
 function getip(){
	var url="../../../wechat/getlocalIP";
	$.ajax({
		type : "get",
		async:false,
		datatype : "json",
		url : url,
		success : function(data) {
			var rst = JSON.parse(data);
			//alert(rst.result)
			localip=rst.result;
		}	
	}); 
} 
//添加已经投票的用户openid进入数据库
function insertip(ip,applyid){
	//alert("openid==="+_openId)
	var heads = new Array("ipaddress","applyid","openid");
	var datas = new Array(ip,applyid,_openId);
	var parser = new Object();
	//alert("本地ip为"+ip+"用户id"+applyid);
	//alert("图片介绍=="+uimagetext+"==是否参与"+uparticipation+"==赛区"+utype+"==更新路径"+imageurl)
	var jsonParserStr = null;//定义空头字符串
	if (IsNotEmpty(datas)) {
		addToParser(heads, datas, "add", parser);
		jsonParserStr = JSON.stringify(parser);
	}
	var url = "../../../applyvoteip/add/insertip";
	$.post(url, {
		"data" : jsonParserStr
	}, function(data) {
		var dt = JSON.parse(data);
		if(dt.result>0){
			alert("投票成功");
			getAllvoteip();
			//history.go(0);
			showAllVote();
		}else{
			alert("添加openid异常");
		}
		console.log(data);
		//saveOwnShopIds();
	});
}


//获得全部投票的ip
function getipbyapplyid(){
	var upid=$("#upid").val();
	//alert("applyid=="+upid)
	var url="../../../applyvoteip/find/applybyidwx";
	$.ajax({
		type : "post",
		async:false,
		data:{"data":upid,"id":_openId},
		datatype : "json",
		url : url,
		success : function(data) {
			var data=JSON.parse(data);
			if(data.result.len>0){
				alert("你已经参与过投票，谢谢关注!")
			}else{
				//alert("openid==="+openId)
				if(openId!='null'){
					vote();
				}else{
					alert("openid获得失败");
				}
				
			}
		}	
	});
}


function showVoteinfo(){
	var localhref=document.location.href;
	localhref=localhref.split("?")[1];
	//alert(localhref)
	localhref=localhref.split("&");
	//alert("前半部分为"+localhref[0]+"\t===="+localhref[1])
	if(localhref[1].split("=")[0]=='openId'){
		//alert("openid为"+localhref[1].split("=")[1]);
		openId=localhref[1].split("=")[1];
	}
	if(localhref[0].split("=")[0]=='id'){
		localhref=localhref[0].split("=")[1];
		$("#upid").val(localhref);
		queryvoteinfobyid(localhref);
	}else{
		alert("查询失败")
	}}

function queryvoteinfobyid(id){
	var url = "../../../apply/find/applybyidwx";
	qmsk.get(url,{"id" : id},function(reponse) {
        var imgurl=getHtmlString( reponse.getValue("imageUrl"));
		//alert(reponse.getValue("imageUrl"));
		$("#imageUrl").attr("src",imgurl);
		$("#applyname").text(reponse.getValue("name"));
		$("#votenum").text(reponse.getValue("votenum"));
		$("#imageUrl").val(reponse.getValue("imageUrl"));
		loadHtmlFile(reponse.getValue("imagetext"));
	});
		
}
function vote(){
	var CurrentVotenum=$("#votenum").text();
	var upid=$("#upid").val();
	//alert("进入修改当前票数为=="+CurrentVotenum+"id为=="+upid)
	var heads = new Array("votenum","id");
	var datas = new Array(parseInt(CurrentVotenum)+1,upid);
	var parser = new Object();
	var jsonParserStr = null;//定义空头字符串
	if (IsNotEmpty(datas)) {
		addToParser(heads, datas, "edit", parser);
		jsonParserStr = JSON.stringify(parser);
	}

	var url = "../../../apply/up/updateVotenum";
	$.post(url, {
		"data" : jsonParserStr
	}, function(data) {
		var dt = JSON.parse(data);
		if(dt.result>0){
			showVoteinfo();
			insertip(localip,upid);
			
		}else{
			alert("投票异常")
		}
		console.log(data);
		//saveOwnShopIds();
		
	});
}

//添加已经投票的用户ip进入数据库
function insertip(ip,applyid){
	//alert("openid==="+openId)
	var heads = new Array("ipaddress","applyid","openid");
	var datas = new Array(ip,applyid,openId);
	var parser = new Object();
	//alert("本地ip为"+ip+"用户id"+applyid);
	//alert("图片介绍=="+uimagetext+"==是否参与"+uparticipation+"==赛区"+utype+"==更新路径"+imageurl)
	var jsonParserStr = null;//定义空头字符串
	if (IsNotEmpty(datas)) {
		addToParser(heads, datas, "add", parser);
		jsonParserStr = JSON.stringify(parser);
	}
	var url = "../../../applyvoteip/add/insertip";
	$.post(url, {
		"data" : jsonParserStr
	}, function(data) {
		var dt = JSON.parse(data);
		if(dt.result>0){
			alert("投票成功");
			getAllvoteip();
			//history.go(0);
			showAllVote();
		}else{
			alert("添加openid异常");
		}
		console.log(data);
		//saveOwnShopIds();
	});
}
function loadHtmlFile(url) {
	qmsk.post('../../../htmlUtils/find/getHtml', {
		'htmlUrl' : url
	}, function(response) {
		var html = response.getValue("htmlStr");
		if(html==''){
			$("#indexUrl").html("");
		}else{
			$("#indexUrl").html(html);
		}
	});
}

</script>
</head>

<body style="background:#ddd;">
<div class="wrapper">
  <div class="container">
  <div class="placeTit"><a href="javascript:history.go(-1)" class="back"></a>主播</div>
    <div class="actor">
      <dl>
     <!--  http://www.scmytv.com:4280/html/user/283/1.png -->
        <dt><img src="" id="imageUrl"></dt>
        <dd><strong id="applyname">李冰</strong>
          <p>当前票数：<span class="red" id="votenum">0</span></p>
        </dd>
      </dl>
      <div style="margin:10px auto 0;" class="bottomBtn">
      	<input type="hidden" id="upid">
        <input type="button" value="立即投票" onclick="getipbyapplyid()" class="pay btn voteOver">
      </div>
    </div>
    <div class="txtImgDet" id="indexUrl">
    	<p>00202020</p>
    </div>
  </div>
</div>
</body>
</html>
